<template>
	<view>
		<image class="iwidth" :src="imgPath+'/static/big/pic/loading.png'" mode="widthFix"></image>
		<view class="bgp loading"></view>
		<image class="mbti rightFly" :src="imgPath+'/static/big/pic/yourMBTI.png'" mode="widthFix"></image>
		<BgMusic ref="bgMusic"/>
	</view>
</template>

<script>
	import http from "@/src/http";
	export default {
		data() {
			return {
				answer: [],
				mbtiType: [],
				mbtiTypeName: ''
			}
		},
		onLoad(options) {
			this.answer = options.answer.split(',')
			console.log('answer',options.answer)
			const typeE = [] , typeI = [], typeS = [] , typeN = [], typeT = [] , typeF = [], typeJ = [] , typeP = []
			this.answer.forEach((element,index) => {
				if(index == 0 || index == 2){
					if(element.includes('A')){
						typeE.push(element)
					}else if(element.includes('B')){
						typeI.push(element)
					}
				}else if(index == 1){
					if(element.includes('A')){
						typeI.push(element)
					}else if(element.includes('B')){
						typeE.push(element)
					}
				}else if(index == 3){
					if(element.includes('A')){
						typeS.push(element)
					}else if(element.includes('B')){
						typeN.push(element)
					}
				}else if(index == 4 || index == 5){
					if(element.includes('A')){
						typeN.push(element)
					}else if(element.includes('B')){
						typeS.push(element)
					}
				}else if(index == 6 || index == 8){
					if(element.includes('A')){
						typeF.push(element)
					}else if(element.includes('B')){
						typeT.push(element)
					}
				}else if(index == 7){
					if(element.includes('A')){
						typeT.push(element)
					}else if(element.includes('B')){
						typeF.push(element)
					}
				}else if(index == 9 || index == 11){
					if(element.includes('A')){
						typeJ.push(element)
					}else if(element.includes('B')){
						typeP.push(element)
					}
				}else if(index == 10){
					if(element.includes('A')){
						typeP.push(element)
					}else if(element.includes('B')){
						typeJ.push(element)
					}
				}
			})
			if(typeE.length >= 2){
				this.mbtiType.push('E')
			}else if(typeI.length >= 2){
				this.mbtiType.push('I')
			}
			if(typeS.length >= 2){
				this.mbtiType.push('S')
			}else if(typeN.length >= 2){
				this.mbtiType.push('N')
			}
			if(typeT.length >= 2){
				this.mbtiType.push('T')
			}else if(typeF.length >= 2){
				this.mbtiType.push('F')
			}
			if(typeJ.length >= 2){
				this.mbtiType.push('J')
			}else if(typeP.length >= 2){
				this.mbtiType.push('P')
			}
			this.mbtiType.forEach(elem=>{
				this.mbtiTypeName += elem
			})
			this.subMbit()
		},
		methods: {
			toResult(){
				uni.redirectTo({
					url:'/pages/activeB/result/index?mbtiType=' + this.mbtiTypeName
				});
			},
			subMbit(){
				const params = {
					answer: this.answer.toString(),
					mbti: this.mbtiTypeName,
				}
				http.submitTest(params).then(res=>{
					setTimeout(()=>{
						this.toResult()
					},1000)
				})
			}
		}
	}
</script>

<style scoped>
.mbti{
	position: absolute;
	z-index: 9;
	width: 225rpx;
  top: 580rpx;
  left: 344rpx;
}
.bgp{
	position: absolute;
	z-index: 6;
	height: 66rpx;
	top: 566rpx;
	left: 333rpx;
	background-color: #369eff;
}
</style>
